package com.fileupload.fileupload.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitMqConfig {

    /**
     * 创建交换机
     * @return
     */
    @Bean
    public DirectExchange getDirectExchange(){
        return new DirectExchange("file-upload-exchange",true, false, null);
    }

    /**
     * 创建队列
     * @return
     */
    @Bean
    public Queue getQueue(){
        return new Queue("file-upload-queue",true,false,false,null);
    }

    /**
     * 绑定队列到交换机
     * @return
     */
    @Bean
    public Binding getBinding(){
        return BindingBuilder.bind(getQueue()).to(getDirectExchange()).with("excel.queue");
    }

}
